﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace BackupManager.Storage
{
    public static class Serializer
    {
        public static string Serialize<T>(this T toSerialize)
        {
            var xmlSerializer = new XmlSerializer(toSerialize.GetType());
            var textWriter = new StringWriter();
            xmlSerializer.Serialize(textWriter, toSerialize);
            return textWriter.ToString();
        }

        public static T Deserialize<T>(string s)
        {
            var xmlSerializer = new XmlSerializer(typeof(T));
            var textReader = new StringReader(s);
            return (T)(xmlSerializer.Deserialize(textReader));
        }
    }
}
